package com.sike.netty.jinjie.codec.protocol.decoder;

import com.alibaba.fastjson.JSONObject;
import com.sike.netty.jinjie.codec.protocol.message.ChatMessage;
import com.sike.netty.jinjie.codec.protocol.message.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

public class StringToObjectDecoder extends MessageToMessageDecoder<String> {

    @Override
    protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        if (msg != null) {
            ChatMessage chatMessage = JSONObject.parseObject(msg,ChatMessage.class);
            out.add(chatMessage);
        }
    }
}
